<template>
    <el-page-header icon="el-icon-arrow-left" @back="$router.replace('/roomplan')" content="默认价格调整">
    </el-page-header>
    <el-divider></el-divider>
    <el-table :data="tableData" style="width: 100%">
        <el-table-column prop="id" v-if="false"></el-table-column>
        <el-table-column type="index" label="序号"></el-table-column>
        <el-table-column prop="typeName" label="房型名称" min-width="50"></el-table-column>
        <el-table-column label="默认工作日价格" min-width="30">
            <template #default="scope">
                <el-input-number v-model="scope.row.workdayPrice" :min="0" :precision="2" :step="10"  size="medium"></el-input-number>
            </template>
        </el-table-column>
        <el-table-column label="默认周末价格" min-width="30">
            <template #default="scope">
                <el-input-number v-model="scope.row.weekendPrice" :min="0" :precision="2" :step="10"  size="medium"></el-input-number>
            </template>
        </el-table-column>
        <el-table-column label="操作" min-width="30">
            <template #default="scope">
                <el-popconfirm title="修改价格将会影响利润,确定吗?" @confirm="saveAndRefresh(scope.row)">
                    <template #reference>
                        <el-button type="primary">保存并刷新</el-button>
                    </template>
                </el-popconfirm>
            </template>
        </el-table-column>
    </el-table>
</template>

<script>
    import {ElMessage} from "element-plus";
    export default {
        name: "default.vue",
        data() {
            return {
                tableData: []
            }
        },
        methods: {
            saveAndRefresh(row) {
                this.axios.put('roomtype/updateDefaultPrice', {
                    id: row.id,
                    workdayPrice: row.workdayPrice,
                    weekendPrice: row.weekendPrice
                }).then(resp => {
                    if (!resp.data.flag) {
                        ElMessage.error(resp.data.msg);
                        return;
                    }
                    ElMessage.success(resp.data.msg);
                    this.$router.replace(this.$route.path);
                });
            }
        },
        created() {
            this.axios.get('roomtype/listDefaultPrice')
                .then(resp => {
                    if (!resp.data.flag) {
                        ElMessage.error(resp.data.msg)
                        return;
                    }
                    this.tableData = resp.data.data.list;
                });
        }
    }
</script>

<style scoped>

</style>